package com.szxx.suit;

import java.util.HashSet;
import java.util.Set;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import com.szxx.constans.PokerGameConstant;
import com.szxx.domain.Card;
import com.szxx.domain.CardShape;
import com.szxx.domain.DdzCard;

@Component
public class DdzSuitTestService extends SuitTestService {
	
	@Value("${laiziNumbers}")
    protected String laiziNumbers;
	
	private Set<Integer> laiziNumberSet = new HashSet<Integer>();
	
	@Override
	public void doSuitTest() {
		if (!StringUtils.isBlank(laiziNumbers)) {
			String[] numberStrs = laiziNumbers.split(",");
			for (String numberStr : numberStrs) {
				laiziNumberSet.add(Integer.valueOf(numberStr));
			}
		}
		super.doSuitTest();
	}
	
	@Override
	public Card transfer2Card(String cardStr) {
		try {
			int number = Integer.valueOf(cardStr).intValue();
			if (number == PokerGameConstant.RED_JOKER_SHAPE_NUM) {
				return new DdzCard(CardShape.RED_JOKER, number).revalue();
			} else if (number == PokerGameConstant.BLACK_JOKER_SHAPE_NUM) {
				return new DdzCard(CardShape.BLACK_JOKER, number).revalue();
			} else if (number > 0 || number <= PokerGameConstant.SINGLE_SHAPE_MAX_NUM) {
				if (laiziNumberSet.contains(number)) {
					return new DdzCard(CardShape.DIAMOND, number, true).revalue();
				} else {
					return new DdzCard(CardShape.DIAMOND, number).revalue();
				}
			}
		} catch (Exception e) {
		}
		return null;
	}

}
